<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>

        // 排序，每个文件都有名字，大小，时间，都可以按照某个属性的值进行排序

        // 电影类
        function File(name,size,time){
            this.name = name
            this.size = size
            this.time = time
        }
        var f1 = new File('jack.avi','400M','1997-12-12')
        var f2 = new File('tom.avi','200M','2017-12-12')
        var f3 = new File('xiaosu.avi','800M','2010-12-12')

        var arr = [f1,f2,f3]

        // arr.sort(function(obj1,obj2){
        //     if(obj1.name>obj2.name){
        //         return 1;
        //     }else if(obj1.name == obj2.name){
        //         return 0;
        //     }else{
        //         return -1;
        //     }
        // })

        function fn(attr){
            return function(obj1,obj2){
                if(obj1[attr]>obj2[attr]){
                    return 1;
                }else if(obj1[attr] == obj2[attr]){
                    return 0;
                }else{
                    return -1;
                }
            }
        }
        let ff = fn('time')
        arr.sort(ff)
        
        for (let i = 0; i < arr.length; i++) {
            console.log(`${arr[i].name}====>${arr[i].size}===>${arr[i].time}`) ;            
        }

        // function fn(){

        // }
        // var ff = fn();
        // arr.sort(ff);


    </script>
</body>
</html>